package com.shop.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.shop.service.GoodsService;
import com.shop.service.impl.GoodsServiceImpl;

/**
 * Servlet implementation class DeleteGoodsServlet
 */
@WebServlet("/deleteGoods.do")
public class DeleteGoodsServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		HttpSession session = req.getSession();
		if(session.getAttribute("admin") == null) {
			resp.sendRedirect("Login.jsp");
		}
		GoodsService gs = new GoodsServiceImpl();
		String idStr = req.getParameter("id");
		try {
			int id = Integer.parseInt(idStr);
			gs.deleteGoods(id);
			resp.sendRedirect("goods.do");
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

}
